package com.epam.cdp.selenium2.core.results.logger;

import org.apache.commons.lang.StringEscapeUtils;

/**
 * Common project logger.
 * 
 * @author mperepelov
 */
public class Logger
{
  private static String getHtmlMessage( String message )
  {
    return StringEscapeUtils.escapeHtml( message );
  }

  public static org.apache.log4j.Logger getLogger()
  {
    return org.apache.log4j.Logger.getRootLogger();
  }

  public static final void fatal( String message )
  {
    getLogger().fatal( getHtmlMessage( message ) );
  }

  public static final void fatal( String message, Throwable t )
  {
    getLogger().fatal( getHtmlMessage( message ), t );
  }

  public static final void error( String message )
  {
    getLogger().error( getHtmlMessage( message ) );
  }

  public static final void error( String message, Throwable t )
  {
    getLogger().error( getHtmlMessage( message ), t );
  }

  public static final void debug( String message, Throwable t )
  {
    getLogger().debug( getHtmlMessage( message ), t );
  }

  public static final void warn( String message, Throwable t )
  {
    getLogger().warn( getHtmlMessage( message ), t );
  }

  public static final void trace( String message )
  {
    getLogger().trace( message );
  }

  public static final void trace( String message, Throwable t )
  {
    getLogger().trace( message, t );
  }

  public static final void info( String message, Throwable t )
  {
    getLogger().info( getHtmlMessage( message ), t );
  }

  public static final void warn( String message )
  {
    getLogger().warn( getHtmlMessage( message ) );
  }

  public static final void info( String message )
  {
    getLogger().info( getHtmlMessage( message ) );
  }

  public static final void debug( String message )
  {
    getLogger().debug( getHtmlMessage( message ) );
  }

  public static final void operation( String message )
  {
    getLogger().log( LoggerLevel.OPERATION, getHtmlMessage( message ) );
  }

  public static final void action( String message )
  {
    getLogger().log( LoggerLevel.ACTION, getHtmlMessage( message ) );
  }

  public static void shutdown()
  {
    org.apache.log4j.LogManager.shutdown();
  }

  public static String getStringMessageFromHtml( String htmlMessage )
  {
    try
    {
      return htmlMessage.replaceAll( "&LT;", "<" ).replaceAll( "&GT;", ">" ).replaceAll( "<BR>", "\n" );
    }
    catch( Exception e )
    {
      return e.getMessage();
    }
  }
}
